<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: ImageSprite</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.sprite</a> ]
    </div>

    <h1>Coverage Summary for Class: ImageSprite (nl.tudelft.jpacman.sprite)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">ImageSprite</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 7)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 15)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.sprite;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.awt.Graphics;
        <i>4</i>&nbsp;import java.awt.GraphicsConfiguration;
        <i>5</i>&nbsp;import java.awt.GraphicsEnvironment;
        <i>6</i>&nbsp;import java.awt.Image;
        <i>7</i>&nbsp;import java.awt.Transparency;
        <i>8</i>&nbsp;import java.awt.image.BufferedImage;
        <i>9</i>&nbsp;
        <i>10</i>&nbsp;/**
        <i>11</i>&nbsp; * Basic implementation of a Sprite, it merely consists of a static image.
        <i>12</i>&nbsp; *
        <i>13</i>&nbsp; * @author Jeroen Roosen
        <i>14</i>&nbsp; */
        <i>15</i>&nbsp;public class ImageSprite implements Sprite {
        <i>16</i>&nbsp;
        <i>17</i>&nbsp; /**
        <i>18</i>&nbsp; * Internal image.
        <i>19</i>&nbsp; */
        <i>20</i>&nbsp; private final Image image;
        <i>21</i>&nbsp;
        <i>22</i>&nbsp; /**
        <i>23</i>&nbsp; * Creates a new sprite from an image.
        <i>24</i>&nbsp; *
        <i>25</i>&nbsp; * @param img
        <i>26</i>&nbsp; * The image to create a sprite from.
        <i>27</i>&nbsp; */
        <b class="nc"><i>28</i>&nbsp; public ImageSprite(Image img) {</b>
        <b class="nc"><i>29</i>&nbsp; this.image = img;</b>
        <i>30</i>&nbsp; }
        <i>31</i>&nbsp;
        <i>32</i>&nbsp; @Override
        <i>33</i>&nbsp; public void draw(Graphics graphics, int x, int y, int width, int height) {
        <b class="nc"><i>34</i>&nbsp; graphics.drawImage(image, x, y, x + width, y + height, 0, 0,</b>
        <b class="nc"><i>35</i>&nbsp; image.getWidth(null), image.getHeight(null), null);</b>
        <i>36</i>&nbsp; }
        <i>37</i>&nbsp;
        <i>38</i>&nbsp; @Override
        <i>39</i>&nbsp; public Sprite split(int x, int y, int width, int height) {
        <b class="nc"><i>40</i>&nbsp; if (withinImage(x, y) &amp;&amp; withinImage(x + width - 1, y + height - 1)) {</b>
        <b class="nc"><i>41</i>&nbsp; BufferedImage newImage = newImage(width, height);</b>
        <b class="nc"><i>42</i>&nbsp; newImage.createGraphics().drawImage(image, 0, 0, width, height, x,</b>
        <i>43</i>&nbsp; y, x + width, y + height, null);
        <b class="nc"><i>44</i>&nbsp; return new ImageSprite(newImage);</b>
        <i>45</i>&nbsp; }
        <b class="nc"><i>46</i>&nbsp; return new EmptySprite();</b>
        <i>47</i>&nbsp; }
        <i>48</i>&nbsp;
        <i>49</i>&nbsp; private boolean withinImage(int x, int y) {
        <b class="nc"><i>50</i>&nbsp; return x &lt; image.getWidth(null) &amp;&amp; x &gt;= 0 &amp;&amp; y &lt;
            image.getHeight(null)</b>
        <i>51</i>&nbsp; &amp;&amp; y &gt;= 0;
        <i>52</i>&nbsp; }
        <i>53</i>&nbsp;
        <i>54</i>&nbsp; /**
        <i>55</i>&nbsp; * Creates a new, empty image of the given width and height. Its
        <i>56</i>&nbsp; * transparency will be a bitmask, so no try ARGB image.
        <i>57</i>&nbsp; *
        <i>58</i>&nbsp; * @param width
        <i>59</i>&nbsp; * The width of the new image.
        <i>60</i>&nbsp; * @param height
        <i>61</i>&nbsp; * The height of the new image.
        <i>62</i>&nbsp; * @return The new, empty image.
        <i>63</i>&nbsp; */
        <i>64</i>&nbsp; private BufferedImage newImage(int width, int height) {
        <i>65</i>&nbsp; GraphicsConfiguration gc = GraphicsEnvironment
        <b class="nc"><i>66</i>&nbsp; .getLocalGraphicsEnvironment().getDefaultScreenDevice()</b>
        <b class="nc"><i>67</i>&nbsp; .getDefaultConfiguration();</b>
        <b class="nc"><i>68</i>&nbsp; return gc.createCompatibleImage(width, height, Transparency.BITMASK);</b>
        <i>69</i>&nbsp; }
        <i>70</i>&nbsp;
        <i>71</i>&nbsp; @Override
        <i>72</i>&nbsp; public int getWidth() {
        <b class="nc"><i>73</i>&nbsp; return image.getWidth(null);</b>
        <i>74</i>&nbsp; }
        <i>75</i>&nbsp;
        <i>76</i>&nbsp; @Override
        <i>77</i>&nbsp; public int getHeight() {
        <b class="nc"><i>78</i>&nbsp; return image.getHeight(null);</b>
        <i>79</i>&nbsp; }
        <i>80</i>&nbsp;
        <i>81</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
